<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>部门添加</title>
		<link rel="stylesheet" href="/static/css/bmtj.css">
	</head>
	<body>
			<div class="">
				<form action=""> 
					<p class="">部门名称:</p><input class="dep_name"  placeholder="请输入部门名称"  type="text">
					<br>
					<p class="">部门编号:</p><input class="dep_id"  placeholder="请输入部门编号"  type="text">
					<br>
					<p class="">部门负责人:</p><input class="department_head"  placeholder="请输入负责人"  type="text">
					<br>
					<p class="">负责人编号:</p><input class="department_head_id"  placeholder="请输入负责人编号"  type="text">
					<br>
					<p class="">部门人数:</p><input class="department_count"  placeholder="请输入人数"  type="text">
					<br>
					<input class="save" type="button" value="保存" onclick="department_add()">
				</form>
			</div>
	</body>
	<script src="/static/js/jquery.min.js"></script>
	<script>
		function department_add(){
			//获取用户输入
			var dep_name = $('.dep_name').val();
			var dep_id = $('.dep_id').val();
			var department_head = $('.department_head').val();
			var department_head_id = $('.department_head_id').val();	
			//封装成json
			var post_data = {
				"dep_name":dep_name,
		                "dep_id":dep_id,
		                "department_head":department_head,
		                "department_head_id":department_head_id,
							};
			console.log(post_data);
			// 向后端发送ajax请求
			$.ajax({
				url:'http://127.0.0.1:8000/v1/divisional/',
				type:'post',
				data:JSON.stringify(post_data),
				contentType:'application/json',
				dataType:'json',
				success:function(res){
					if(res.code == 200){
						alert('添加成功');				
					}else{
						alert(res.error);
					}
				}
			})
			
		}
	
	
	</script>
</html>
